home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
sound
/
fftscop4.zip
/
FFTSCOPE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-30
|
30KB
|
1,392 lines
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
#include <mem.h>
#include <math.h>
#define TWO_PI ((double)2.0 * M_PI)
typedef unsigned char DacPalette256[256][3];
unsigned char far *VGAmem;
struct text_info tiGFX;
struct REGPACK regp;
union REGS reg;
int Linecolor=1,WritePage=0,HighSpeed=0,Triggerbuffer=999;
int minX=0,minY=0,maxx=320,maxy=200;
DacPalette256 Hallo;
/* Globals */
int samples, power;
double real[2048], imag[2048], max, Pegel=10,FFTmax;
FILE *fpi, *fpo;
/* Prototypes and forward declarations */
void fft(void), max_amp(void);
int permute(int);
double magnitude(int);
void dspwrite ( unsigned char );
unsigned char dspread ( void );
unsigned Buffer[2048];
unsigned SBuffer[8900];
unsigned char far *data;
unsigned char far *aligned;
unsigned char far aligned_physical;
/* Getvgapalette256 gets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* getvgapalette256(&dac256); */
void getvgapalette256(DacPalette256 *PalBuf)
{
regp.r_ax = 0x1017;
regp.r_bx = 0;
regp.r_cx = 256;
regp.r_es = FP_SEG(PalBuf);
regp.r_dx = FP_OFF(PalBuf);
intr(0x10,®p);
}
/* Setvgapalette256 sets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* setvgapalette256(&dac256); */
void setvgapalette256(DacPalette256 *PalBuf)
{
regp.r_ax = 0x1012;
regp.r_bx = 0;
regp.r_cx = 256;
regp.r_es = FP_SEG(PalBuf);
regp.r_dx = FP_OFF(PalBuf);
intr(0x10,®p);
}
void Grafik(int GFXmode) // 13, 14, 17mono, 18, 19vga, -1,3
{ //320x200, 640x200, 640x480, 640x480, 320x200, text
VGAmem=(char far *)MK_FP(0xa000,0);
if (GFXmode>=0)
{
gettextinfo(&tiGFX);
regp.r_ax = GFXmode;
intr(0x10,®p);
}
if (GFXmode<0)
{
regp.r_ax = tiGFX.currmode;
intr(0x10,®p);
}
}
void Putpixel(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = Linecolor;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
void Putpixel2(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = 0;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
void Putpixel3(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = 235-y;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
int Getpixel(int x, int y)
{
if(x<minX)return 0;
if(y<minY)return 0;
if(x>=maxx)return 0;
if(y>=maxy)return 0;
reg.h.ah = 0x0d;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
return reg.h.al;
}
void singlecolor256(int nr,int r,int g,int b)
{
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void singlecolor16(int nr,int r,int g,int b)
{
reg.h.ah=0x10;
reg.h.al=0x07;
reg.h.bl=nr;
int86(0x10,®,®);
nr=reg.h.bh;
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void linie(double x1,double y1,double x2,double y2)
{
double a,b,dx,dy,e;
dx=x1-x2;
dy=y1-y2;
if(dx==0)
{
if(dy>=0) for(e=y2;e<=y1;e++)Putpixel(x1,e);
else for(e=y1;e<=y2;e++)Putpixel(x1,e);
return;
}
if(dy==0)
{
if(dx>=0) for(e=x2;e<=x1;e++)Putpixel(e,y1);
else for(e=x1;e<=x2;e++)Putpixel(e,y1);
return;
}
e=y1-(dy*x1)/dx;
if(abs(dx)>=abs(dy))
{
if(dx>=0)
{
for(a=x2;a<=x1;a++){ b=e+(a*dy)/dx; Putpixel(a,b); }
}
else
{
for(a=x1;a<=x2;a++){ b=e+(a*dy)/dx; Putpixel(a,b); }
}
}
if(abs(dx)<abs(dy))
{
if(dy>=0)
{
for(a=y2;a<=y1;a++){ b=((a-e)*dx)/dy; Putpixel(b,a); }
}
else
{
for(a=y1;a<=y2;a++){ b=((a-e)*dx)/dy; Putpixel(b,a); }
}
}
}
void MakePalette()
{
int frag;
for(frag=0;frag<256;frag++)
{
if(frag<32)
{
Hallo[frag][0]=0;
Hallo[frag][1]=0;
Hallo[frag][2]=2*frag;
}
if((frag>=32)&&(frag<96))
{
Hallo[frag][0]=0;
Hallo[frag][1]=(frag-32);
Hallo[frag][2]=(95-frag);
}
if((frag>=96)&&(frag<128))
{
Hallo[frag][0]=2*(frag-96);
Hallo[frag][1]=63;
Hallo[frag][2]=0;
}
if((frag>=128)&&(frag<192))
{
Hallo[frag][0]=63;
Hallo[frag][1]=(191-frag);
Hallo[frag][2]=(frag-128);
}
if(frag>=192)
{
Hallo[frag][0]=63;
Hallo[frag][1]=0;
Hallo[frag][2]=0;
if(frag<223)Hallo[frag][2]=2*(222-frag);
}
}
setvgapalette256(&Hallo);
}
//------------------------------------------------------------------------------
void dspwrite ( unsigned char c )
{
while(inportb(0x022C)&0x80);
outportb(0x022C,c);
}
//------------------------------------------------------------------------------
void sbinit ( void )
{
unsigned short x;
inportb(0x022E);
outportb(0x0226,0x01);
inportb(0x0226);
inportb(0x0226);
inportb(0x0226);
inportb(0x0226);
outportb(0x0226,0x00);
for(x=0;x<100;x++)
{
if(inportb(0x022E)&0x80)
{
if(inportb(0x022A)==0xAA) break;
}
}
if(x==100)
{
printf("Sound Blaster not found at 0220h\n");
exit(1);
}
}
//------------------------------------------------------------------------------
void sbmalloc ( void )
{
unsigned long physical;
data=farmalloc(80000L);
if(data==NULL)
{
printf("Memory Allocation Error\n");
exit(1);
}
physical=((unsigned long)FP_OFF(data))+(((unsigned long)FP_SEG(data))<<4);
physical+=0x0FFFFL;
physical&=0xF0000L;
aligned_physical=(physical>>16)&15;
aligned=MK_FP(((unsigned short)aligned_physical<<12)&0xF000,0);
}
//------------------------------------------------------------------------------
void sbsettc ( unsigned char tc )
// tc = time constant = 256L - (1000000UL/samples per second)
{
inportb(0x022E);
dspwrite(0x40);
dspwrite(tc);
}
//------------------------------------------------------------------------------
void sbrec ( unsigned short len )
// len = number of bytes to record to unsigned char *aligned (<=65000)
{
len--;
outportb(0x0A,0x05);
outportb(0x0C,0x00);
outportb(0x0B,0x45);
outportb(0x02,0);
outportb(0x02,0);
outportb(0x83,aligned_physical);
outportb(0x03,(unsigned char)(len&0xFF));
outportb(0x03,(unsigned char)((len>>8)&0xFF));
outportb(0x0A,0x01);
dspwrite(0x24);
dspwrite((unsigned char)(len&0xFF));
dspwrite((unsigned char)((len>>8)&0xFF));
}
//------------------------------------------------------------------------------
void sbrec2 ( unsigned short len )
// len = number of bytes to record to unsigned char *aligned (<=65000)
{
len--;
outportb(0x0A,0x05);
outportb(0x0C,0x00);
outportb(0x0B,0x45);
outportb(0x02,0);
outportb(0x02,0);
outportb(0x83,aligned_physical);
outportb(0x03,(unsigned char)(len&0xFF));
outportb(0x03,(unsigned char)((len>>8)&0xFF));
outportb(0x0A,0x01);
dspwrite(0x48);
dspwrite((unsigned char)(len&0xFF));
dspwrite((unsigned char)((len>>8)&0xFF));
dspwrite(0x99);
}
//------------------------------------------------------------------------------
unsigned short dmacount ( void )
{
unsigned short x;
x=inportb(0x03);
x|=inportb(0x03)<<8;
if(x==0xFFFF) inportb(0x022E);
return(x);
}
//------------------------------------------------------------------------------
void recording(int e,int f)
{
int m,n=Triggerbuffer -e -30,o;